package org.ydeity.lucene.configuration;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.ydeity.lucene.convert.MappingLuceneConvert;
import org.ydeity.lucene.core.LuceneTemplate;

@Configuration
@EnableConfigurationProperties(LuceneProperties.class)
public class AutoConfigurationClass {

    @Autowired
    private LuceneProperties properties;

    /**
     * 当spring容器中没有这个Bean的时候才进行下一步
     */
    @Bean
    @ConditionalOnMissingBean
    public LuceneTemplate luceneTemplate(){
        return new LuceneTemplate(new MappingLuceneConvert(properties));
    }
}